﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Lesson19 : MonoBehaviour
{
    public EventTrigger trigger;
    private void Start()
    {
        if (trigger)
        {
            //声明一个希望监听的事件对象
            EventTrigger.Entry downEntry = new EventTrigger.Entry();
            //申明事件的类型
            downEntry.eventID = EventTriggerType.PointerDown;
            //监听函数关联
            downEntry.callback.AddListener((data) => {
                Debug.LogFormat("鼠标按下...");
            });
            trigger.triggers.Add(downEntry);

            //鼠标抬起
            EventTrigger.Entry upEntry = new EventTrigger.Entry();
            upEntry.eventID = EventTriggerType.PointerUp;
            upEntry.callback.AddListener(PointerUp);
            trigger.triggers.Add(upEntry);
        }
    }

    public void PointerUp(BaseEventData eventData) 
    {
        Debug.LogFormat("鼠标抬起...");
    }

    public void TestPointerEnter(BaseEventData eventData)
    {
        PointerEventData point = eventData as PointerEventData;
        Debug.LogFormat("TestPointerEnter pos:{0}......", point.position);
    }

    public void TestPointerLeave(BaseEventData eventData)
    {
        PointerEventData point = eventData as PointerEventData;
        Debug.LogFormat("TestPointerLeave pos:{0}......", point.position);
    }
}
